package com.wuhunyu.controller;

import com.wuhunyu.commonutils.query.CommonQuery;
import com.wuhunyu.commonutils.result.CommonResult;
import com.wuhunyu.entities.EduTeacher;
import com.wuhunyu.query.EduTeacherQuery;
import com.wuhunyu.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author wuhunyu
 * @since 2021-01-12
 */
@RestController
@RequestMapping("/eduTeacher")
@ApiModel("讲师管理")
//@CrossOrigin
public class EduTeacherController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @ApiOperation("查询全部讲师")
    @PostMapping("/list")
    public CommonResult selectAllTeacher(@RequestBody(required = false) EduTeacherQuery eduTeacherQuery) {
        return eduTeacherService.selectAllTeacher(eduTeacherQuery);
    }

    @ApiOperation("逻辑删除指定讲师")
    @DeleteMapping("/{id}")
    public CommonResult deleteTeacher(@ApiParam("指定讲师ID") @PathVariable("id") String id) {
        return eduTeacherService.deleteTeacher(id);
    }

    @ApiOperation("新增教师")
    @PostMapping("/insert")
    public CommonResult insertTeacher(@RequestBody(required = false) EduTeacher eduTeacher) {
        return eduTeacherService.insertTeacher(eduTeacher);
    }

    @ApiOperation("查询教师")
    @GetMapping("/{id}")
    public CommonResult selectTeacherById(@ApiParam("指定讲师ID") @PathVariable("id") String id) {
        return eduTeacherService.selectTeacherById(id);
    }

    @ApiOperation("更新教师信息")
    @PostMapping("/update")
    public CommonResult updateTeacher(@RequestBody(required = false) EduTeacher eduTeacher) {
        return eduTeacherService.updateTeacher(eduTeacher);
    }

    @ApiOperation("为下拉框查询教师信息")
    @GetMapping("/list")
    public CommonResult selectTeacherForSelect() {
        return eduTeacherService.selectTeacherForSelect();
    }

    @ApiOperation("根据讲师id查询前四条讲师记录")
    @GetMapping("/selectTeachers")
    public CommonResult selectTeachers() {
        return eduTeacherService.selectTeachers();
    }

    @PostMapping("/selectTeachersForFront")
    public CommonResult selectTeachersForFront(@RequestBody(required = true) CommonQuery commonQuery) {
        return eduTeacherService.selectTeachersForFront(commonQuery);
    }

    @GetMapping("/selectCourseByTeacherId/{teacherId}")
    public CommonResult selectCourseByTeacherId(@PathVariable("teacherId") String teacherId) {
        return eduTeacherService.selectCourseByTeacherId(teacherId);
    }

}

